package Example;
import java.util.Scanner;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2024-01-14  19:26
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MultiplicationCalculator extends JFrame {

    private JTextField num1Field, num2Field;
    private JButton multiplyButton;
    private JTextArea resultArea;

    public MultiplicationCalculator() {
        setTitle("乘法计算器");
        setSize(300, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new GridLayout(4, 1));

        num1Field = new JTextField();
        num2Field = new JTextField();
        multiplyButton = new JButton("乘法");
        resultArea = new JTextArea();

        multiplyButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                multiplyNumbers();
            }
        });

        add(new JLabel("输入第一个数字:"));
        add(num1Field);
        add(new JLabel("输入第二个数字:"));
        add(num2Field);
        add(multiplyButton);
        add(new JLabel("结果:"));
        add(resultArea);
    }

    private void multiplyNumbers() {
            double num1 = Double.parseDouble(num1Field.getText());
            double num2 = Double.parseDouble(num2Field.getText());
            double result = num1 * num2;
            resultArea.setText(String.valueOf(result));
    }

    public static void main (String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MultiplicationCalculator().setVisible(true);
            }
        });
    }
}

